<!-- 待办任务 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" class="search-form" size="small" :inline="true" label-width="">
      <el-form-item label="任务名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入任务名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- @selection-change="handleSelectionChange" -->
    <el-table v-loading="loading" :data="tableList" :max-height="height">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" prop="id" fixed="left">
        <template slot-scope="scope">
          <span>{{scope.$index+1 + (queryParams.pageNum-1)*queryParams.pageSize}}</span>
        </template>
      </el-table-column>
      <el-table-column label="编号" align="center" prop="instanceId" />
      <el-table-column label="类型" align="center" prop="module">
        <template slot-scope="scope">
          <span v-if="scope.row.module == 'batch'">呈批件</span>
          <span v-else-if="scope.row.module == 'dispatch'">发文</span>
          <span v-else-if="scope.row.module == 'message'">收文</span>
        </template>
      </el-table-column>
      <el-table-column label="任务名称" align="center" prop="itemName" min-width="200" :show-overflow-tooltip="true" />
      <el-table-column label="状态" align="center" prop="isHandle">
        <template slot-scope="scope">
          <span v-if="scope.row.isHandle == 0">未处理</span>
          <span v-else>已处理</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleApproval(scope.row)"
          >处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { waitHandleTasksList,waitTaskHandle } from "@/api/system/processModelManage";

export default {
  name: "WaitHandleTasks",
  components: {},
  data() {
    return {
      height: (document.documentElement.clientHeight || document.body.clientHeight)-220,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 新闻资讯表格数据
      tableList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemName: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询流程模型管理列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams)
      waitHandleTasksList(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 跳转审批界面处理 */
    handleApproval(row){
      var params = {
        instanceId: row.instanceId,
        module: row.module
      }
      waitTaskHandle(params).then((res)=>{
        if(res.code == 200){
          if(JSON.stringify(res.data) == '{}'){
            this.msgError('当前没有可处理的任务')
            return false;
          }
          var ress = ''
          if(params.module == 'batch'){
            //呈批件
            ress = res.data.bizBatchVo
          }else if(params.module == 'dispatch'){
            //发文
            ress = res.data.bizDispatchVo
          }else if(params.module == 'message'){
            //收文
            ress = res.data.bizMessageVo
          }
          if(!ress || !ress.id || !ress.task){
            this.msgError('当前没有可处理的任务')
            return false;
          }
          if(params.module == 'batch'){
            //呈批件
            this.$store.dispatch('tagsView/delView', {name: 'ApprovalDoc'}).then(({ visitedViews }) => {
              this.$router.push({
                name: 'ApprovalDoc',
                params: {
                  docId: ress.id,
                  taskId: ress.task,
                  isApproval: true
                }
              })
            })
          }else if(params.module == 'dispatch'){
            //发文
            this.$store.dispatch('tagsView/delView', {name: 'ApprovalPost'}).then(({ visitedViews }) => {
              this.$router.push({
                name: 'ApprovalPost',
                params: {
                  docId: ress.id,
                  taskId: ress.task,
                  isApproval: true
                }
              })
            })
          }else if(params.module == 'message'){
            //收文
            this.$store.dispatch('tagsView/delView', {name: 'ApprovalReceipt'}).then(({ visitedViews }) => {
              this.$router.push({
                name: 'ApprovalReceipt',
                params: {
                  docId: ress.id,
                  taskId: ress.task,
                  isApproval: true
                }
              })
            })
          }
        }
      })
    }
  }
};
</script>
